package isometric
{
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	import starling.display.Sprite;
	
	public class IsoObject extends Sprite
	{
		private var _position:Point3D;
		private var _size:Number;
		private var _walkable:Boolean;
		public static const Y_CORRECT:Number = Math.cos(-Math.PI / 6) * Math.SQRT2; 
		private var _index:int = 0 ;
		public function IsoObject(size:Number)
		{
			this._size = size;
			this._position = new  Point3D();
		}

		public function get index():int
		{
			return _index;
		}

		public function set index(value:int):void
		{
			_index = value;
		}

		protected function updateScreenPosition():void{
			var point:Point = IsoUtils.isoToScreen(this._position);
			super.x = point.x;
			super.y = point.y;
		}
		
		public function get walkable():Boolean
		{
			return _walkable;
		}

		public function set walkable(value:Boolean):void
		{
			_walkable = value;
		}

		public function get size():Number
		{
			return _size;
		}

		public function set size(value:Number):void
		{
			_size = value;
		}

		override public function get x():Number{
			return this._position.x;
		}
		
		override public function set x(value:Number):void{
			this._position.x = value;
			this.updateScreenPosition();
		}
		
		override public function get y():Number{
			return this._position.x;
		}
		
		override public function set y(value:Number):void{
			this._position.y = value;
			this.updateScreenPosition();
		}
		
		public function set z(value:Number):void { 
			this._position.z = value;
			this.updateScreenPosition();
		 } 
		
		public function get z():Number { 
			return this._position.z;
		} 
		
		public function get position():Point3D
		{
			return _position;
		}

		public function set position(value:Point3D):void
		{
			_position = value;
			this.updateScreenPosition();
		}
		
		public function get depth():Number{
			return (this._position.x + this._position.z*0.866 - this._position.y * 0.707);
		}

		public function  get rect():Rectangle{
			return new Rectangle(this.x - this.size/2 ,this.z - size/2,this.size,this.size);
		}
	}
}